package com.manolovn.trianglify.util;

import com.manolovn.trianglify.annotations.Nullable;

/**
 * Preconditions (extracted from guava)
 */
public class Preconditions {
    private Preconditions() {
    }

    /**
     * this method will check reference is not null
     *
     * @param reference refers to type specfic reference
     * @return type specific object
     */
    public static <T> T checkNotNull(T reference) {
        if (reference == null) {
            throw new NullPointerException();
        }
        return reference;
    }

    /**
     * this method will check arguments with expression
     *
     * @param expression refers to boolean expression
     * @param errorMessage shows errorMessage if expression is invalid
     */
    public static void checkArgument(boolean expression, @Nullable Object errorMessage) {
        if (!expression) {
            throw new IllegalArgumentException(String.valueOf(errorMessage));
        }
    }
}
